<?php
require_once("config.php");
////程序设计：℃冻番茄 QQ:7279915 E-mail:web@ye55.com www.phpd.cn
//发信息
if($_GET['act']=='send'){
	$msg=$_POST['msg'];
	$user=$_POST['user'];
	if(empty($msg) || empty($user)){
		$return['msg']='聊天内容或昵称不能为空';
	}else{
		$time=time();
		if($db->insert("insert into `chat_message` (`msg`,`user`,`time`) values ('$msg','$user','$time')")){
			$return['msg']=true;
		}else{
			$return['msg']="err";
		}
	}
	echo json_encode($return);
}elseif($_GET['act']=='display'){
	if(isset($_POST['mid'])){
		$s=" where `mid`>'".$_POST['mid']."' ";
	}else{
		$s='';
	}
	$sql="select * from `chat_message` $s order by `mid` limit 60";
	$total=$db->getcount($sql);
	if($total==0){
		$a=0;
		$b=$_POST['mid'];
	}else{
		$result=$db->query($sql);
		while($row=$db->getarray($result)){
			$row['time1']=date('m-d H:i:s',$row['time']);
			$a[]=$row;
			$b=$row['mid'];
		}
	}
	$ccc=array('list'=>$a,'mid'=>$b);
	echo json_encode($ccc);
}
?>